package com.xiaoyu.cloudmusic.config;

import com.xiaoyu.cloudmusic.data.GlobalData;
import com.xiaoyu.cloudmusic.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 启动全局数据存储定时器
 */
@Component
@EnableScheduling
public class GlobalDataTasks {
    @Autowired
    AdminService adminService;
    /**
     * 每周0点自动将统计数据存入数据库
     */
    @Scheduled(cron = "0 0 0 ? * 1")
    public void SaveGlobalData(){
            adminService.SaveMusicStyleCount(GlobalData.musicStyleCountMap);
            GlobalData.musicStyleCountMap.clear();
    }

}
